import os
import sys


def get_abs_path(*args):
    base_path = get_base_path('tb_send')
    current_dir = os.path.join(base_path, os.path.join(*args))
    current_dir = os.path.abspath(current_dir)
    return current_dir


def get_base_path(spec_name):
    base_dir = os.path.dirname(os.path.abspath(__file__))
    current_path = os.path.dirname(base_dir)
    if spec_name not in current_path.lower():
        sys.exit("please don't modify project name:{}".format(spec_name))
    else:
        while True:
            pardir, now_dir = os.path.split(current_path)
            if spec_name in now_dir.lower():
                return os.path.join(pardir, now_dir)
            current_path = pardir
